package org.tloss.web.editor.form.editors.command;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.jface.action.IMenuManager;
import org.tloss.web.editor.model.command.Assign;
import org.tloss.web.editor.model.command.Else;
import org.tloss.web.editor.model.command.If;
import org.tloss.web.editor.model.command.LoadEnity;
import org.tloss.web.editor.model.command.Replace;
import org.tloss.web.editor.model.command.Reply;

public class MenuFactory {
	public List<MenuItem> initInsertInto(IMenuManager manager,
			final AbstractCommandElement commandElement,
			final IResourceChangeListener listener) {
		List<MenuItem> items = new ArrayList<MenuItem>();
		getCommonItem(items, commandElement, listener);
		return items;
	}

	protected void getCommonItem(List<MenuItem> items,
			final AbstractCommandElement commandElement,
			final IResourceChangeListener listener) {
		items.add(new MenuItem() {
			public String getText() {
				return "IF";
			}

			public AbstractCommandElement getElement() {
				return new IfElement(new If(), listener);
			}
		});
		items.add(new MenuItem() {
			public String getText() {
				return "Reply";
			}

			public AbstractCommandElement getElement() {
				return new ReplyElement(new Reply(), listener);
			}
		});
		items.add(new MenuItem() {
			public String getText() {
				return "Assign";
			}

			public AbstractCommandElement getElement() {
				return new AssignElement(new Assign(), listener);
			}
		});
		items.add(new MenuItem() {
			public String getText() {
				return "Replace";
			}

			public AbstractCommandElement getElement() {
				return new ReplaceElement(new Replace(), listener);
			}
		});
		items.add(new MenuItem() {
			public String getText() {
				return "LoadEnity";
			}

			public AbstractCommandElement getElement() {
				return new LoadEnityElement(new LoadEnity(), listener);
			}
		});
	}

	public List<MenuItem> initNext(IMenuManager manager,
			final AbstractCommandElement commandElement,
			final IResourceChangeListener listener) {
		List<MenuItem> items = new ArrayList<MenuItem>();
		getCommonItem(items, commandElement, listener);
		if (commandElement instanceof IfElement) {
			items.add(new MenuItem() {
				public String getText() {
					return "Else";
				}

				public AbstractCommandElement getElement() {
					return new ElseElement(new Else(), listener);
				}
			});
		}
		return items;
	}
}
